package com.xiaouyudeguang.common.utils;

import java.util.HashMap;
import java.util.Map;

public class JavaType {

    private static final Map<String, String> typeMap = new HashMap<String, String>();

    static {
        typeMap.put("BIGINT", "Long");
        typeMap.put("INT", "Integer");
        typeMap.put("VARCHAR", "String");
        typeMap.put("CHAR", "String");
        typeMap.put("TEXT", "String");
        typeMap.put("DATETIME", "LocalDateTime");
        typeMap.put("DOUBLE", "BigDecimal");
    }

    public static void addType(String columnType, String javaType) {
        typeMap.put(columnType, javaType);
    }

    public static String getJavaType(String columnType) {
        if (columnType.contains("(")) {
            columnType = columnType.substring(0, columnType.indexOf("("));
        }
        String javaType = typeMap.get(columnType);
        if (StringUtils.isBlank(javaType)) {
            javaType = typeMap.get(columnType.toUpperCase());
        }
        return javaType;
    }
}